let app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab_id:0,
    data:'',
    dataList:'',
    cardList:'',
    src:'https://wx1.sinaimg.cn/mw1024/005QJNqdgy1frr3qq0s1vj30im05kdfv.jpg',
    hiddenLoading:false,
    hoarding_id:'' // 优惠卷id
  },
  /*生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success(res) {
        that.setData({
          hei: res.windowHeight - 30
        })
      }
    })
    wx.request({
      url: app.data.url +'/hoardingInstruction',
      header: app.getHeader(),
      success:function(res){
        that.setData({
          desc: res.data.hoardingInfo[0],
        })
      }
    })
    that.getList()
  },
  getList(){
    const that = this
    wx.request({
      url: app.data.url + '/hoardingList',
      method: "POST",
      header: app.getHeader(),
      success: function (res) {
        that.setData({
          myHoardingArr: res.data.myHoardingArr,
          otherHoarding: res.data.otherHoarding
        })
      }
    })
  },
  activeBtn(e){ // 参加活动
    const that= this
    let param = {}
    param.hoarding_id = e.currentTarget.dataset.id
    // console.log("hoarding_id",e.currentTarget.dataset.id)
    that.setData({
      hoarding_id: e.currentTarget.dataset.id
    })
    console.log(that.data.hoarding_id)
    param.discount_price = e.currentTarget.dataset.price
    wx.request({
      url: app.data.url + '/customerHoarding',
      method: "POST",
      data: param,
      header: app.getHeader(),
      success: function (res) {
        console.log("customerHoarding",res)
        if (res.data.appId){
          const order = res.data
          wx.requestPayment({
            'timeStamp': order.timeStamp,
            'nonceStr': order.nonceStr,
            'package': order.package,
            'signType': order.signType,
            'paySign': order.paySign,
            success: function (res) {
              console.log("支付结果",res)
              that.corner()
              that.getList()
              wx.showToast({
                title: "参与成功!",
                duration: 500,
              });
            }
          })
        }
      }
    })
  },
  corner: function () {// 参加囤票活动支付成功
    var that = this
    wx.request({ 
      url: app.data.url + '/addHoarding',
      method: "POST",
      data: {
        hoarding_id: that.data.hoarding_id
      },
      header: app.getHeader(),
      success: function (res) {
        console.log("参加囤票活动支付成功", res)
      }
    })

  },
  chongzhi(){
    wx.navigateTo({
      url: '../recharge/recharge',
    })
  },
  acticve:function(e){
    var that=this;
    var id =e.currentTarget.dataset.tab;
    that.setData({
      tab_id:id
    })
  },
  // 路由跳转：月度军令状
  yue:function(e){
    let id =e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../yue/yue?id='+id,
    })
  },
  //路由跳转：年卡详情
  year_detail:function(e){
    var that =this;
    var id =e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../year_detail/year_detail?id='+id,
    })
  },
  record:function(e){
    let that =this;
    let id =e.currentTarget.dataset.id
    // console.log(id)
    wx.navigateTo({
      url: '../record/record?id='+id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})